﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileDB;

namespace Rem.Objects.Forms
{
    public class BaseForm : Form
    {
        //public static RemDatabaseEntities Database = null;
        
        public static FormsCollection Forms = new FormsCollection();
        public static event FormOperationHandler FormFocused;
        
        public static event FormOperationHandler FormTitleChanged;
        public bool ReadOnly { get; set; }

        public BaseForm(BaseObjectTypes baseType, string text)
        {
            this.BaseType = baseType;
            this.Text = text;
            this.MaximizeBox = false;
            InitBaseForm();
        }
        public BaseForm(string text)
            : this(BaseObjectTypes.None, text)
        {
        }
        public BaseForm()
            : this(string.Empty)
        {

        }
        public void InitBaseForm()
        {
            this.TextChanged += (sender, eventarg) =>
            {
                if (FormTitleChanged != null)
                {
                    FormTitleChanged(this);
                }
            };
            Forms.Add(this);
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            Forms.Remove(this);
        }
        public virtual bool Save()
        {
            if (Saved != null)
                Saved(this.Data, null);
            return true;
        }
        public event EventHandler Saved;
        public EventHandler Deleted { get; set; }
        public virtual BaseObjectTypes BaseType { get; set; }
        protected object Data;
    }
}
